#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

import unittest

# SCRATCH

class Pydoku(object):
    def __init__(self, base):
        self.dimension = base

    def fill(self, guesses):
        self.solutions = guesses

    def solve(self):
        return [self.solutions]

 
# unary sudoku is in the 0 number system
# there is only one sudoku puzzle here!

# 'X' with one solution: '0'
# no hints, still minimal!

# ENDIF

class BasicPydokuTest(unittest.TestCase):
    def test_unary_sudoku (self):
        su = Pydoku (1)
        # the unary sudoku has dimension 1 (one square)
        self.failUnlessEqual (1, su.dimension)

        # solve manually
        su.fill('0')

        # 'solve' really just verify here, as it is already solved
        solutions = su.solve ()
        self.failUnlessEqual (1, len(solutions))
        self.failUnlessMatch ('0', solutions[0])

    def failUnlessMatch(self, expect, solution):
        for (l1, l2) in zip(expect.splitlines(), solution.splitlines()):
            self.failUnlessEqual (l1.strip(), l2.strip())

    def test_binary_sudoku (self):
        """ 0 1 
            1 0"""
        su = Pydoku (2)
        # the binary sudoku has dimension 2 (two by two squares)
        self.failUnlessEqual (2, su.dimension)

        # solve manually
        su.fill("""0 1
                   1 0""")

        # 'solve' really just verify here, as it is already solved
        solutions = su.solve ()
        self.failUnlessEqual (1, len(solutions))
        self.failUnlessMatch ("""0 1
                                 1 0""", solutions[0])
        

if __name__ == '__main__':
    unittest.main()
